//商品类型tree管理.js


$(document).ready(function(){
	var t = $("#treeDemo");
	t = $.fn.zTree.init(t, setting, JSON.parse(ztreelist));
	demoIframe = $("#testIframe");
	setIframeHeight("testIframe");
});


var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("tree");
				demoIframe.attr("src",path+"/prodtype/to_edit_prodtype?id="+treeNode.id);
				return true;

		}
	}
};

		
var code;
		
function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}

/**
 * ifream高度自适应
 * @param iframeId
 */
function setIframeHeight(iframeId) {
	var iframe = document.getElementById(iframeId);
	if(iframe) {
		var height1 = 530;
		var height2 = document.body.clientHeight - 70;
		var height = Math.max(height1, height2);
		iframe.height = height;
	}
}

window.onresize = function() {
	setIframeHeight("testIframe");
}